﻿using System;
using System.Reflection;

namespace Hydra.Core
{
    internal class HydraCallback : IHydraCallback
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        private IPayload _payload;

        public void ApplyDetours(byte[] assembly)
        {
            _payload = (IPayload)Assembly.Load(assembly).
                CreateInstance("Hydra.Fake.Payload");
            _payload.Apply();
            log.InfoFormat("ApplyDetours->{0}", assembly.Length);
        }

        public void ReleaseDetours()
        {
            _payload.Undo();
            log.Info("ReleaseDetours");
        }
    }

    public interface IPayload
    {
        int Apply();
        int Undo();
    }
}